import { getComments, getDetail } from '../../api/detail'
import { getToken, setToken, removeToken, setRoles, getRoles, removeRoles } from '../../utils/auth'
import moment from 'moment';
// import logo from '@/assets/img/logo.jpg'
const home = {
  state: {
    detail: {
			goods_desc:'',
		},
		comments: [],
  },

  mutations: {
    
		SET_COMMENTS(state, comments) {
      state.comments = comments
    },
		SET_DETAIL(state, detail) {
      state.detail = detail
    },
		
    
    
  },

  actions: {
    getComments({ commit }, param) {
      return new Promise((resolve, reject) => {
        getComments(param).then(data => {
          let [error, res]  = data;
					res.data.reviews.forEach((item)=>{
						item.time = moment(item.updated_at).format("YYYY/MM/DD HH:mm")
					})
					// console.log(res.data.reviews);
          commit('SET_COMMENTS', res.data.reviews)
          resolve(res.data)
        }).catch(error => {
					console.log(error);
          reject(error.data)
        })
      })
    },
		getDetail({ commit }, param) {
      return new Promise((resolve, reject) => {
        getDetail(param).then(data => {
          let [error, res]  = data;
          commit('SET_DETAIL', res.data.product)
          resolve(res.data)
        }).catch(error => {
					console.log(error);
          reject(error.data)
        })
      })
    },
		
  }
}

export default home
